package com.example.springbootmvc.config;

import com.example.springbootmvc.servlet.KVDispatcherServlet;
import com.example.springbootmvc.servlet.KVDispatcherServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MvcConfig {
    @Bean
    @Lazy(false)
    public ServletRegistrationBean statViewServlet() {
        System.out.println("我执行了~");
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new KVDispatcherServlet(), "/demo/*");
        Map<String, String> initParams = new HashMap<>();
        initParams.put("contextConfigLocation", "application.properties");
        servletRegistrationBean.setInitParameters(initParams);
        return servletRegistrationBean;
    }
}
